<?php
require_once('libs/controller.php');

class LController extends Controller{

	public $results = array();
	public $parentGroup;
	public function execute(){
		$this->head->setTitle($this->cfg->sitename);
		if(isset($_POST['login'])){
			$_SESSION['login'] = true;
			$_SESSION['access'] = true;
			header("Location: http://".$this->head->baseURL);
		}
		if(isset($_GET['task']) && $_GET['task'] == 'logout'){
			session_destroy();
			header("Location: http://".$this->head->baseURL);
		}
	}
	public function login(){
		$this->head->setTitle($this->cfg->sitename);
		if(isset($_POST['login'])){
			$_SESSION['login'] = true;
			$_SESSION['access'] = true;
			header("Location: http://".$this->head->baseURL);
		}
		if(isset($_GET['task']) && $_GET['task'] == 'logout'){
			session_destroy();
			header("Location: http://".$this->head->baseURL);
		}
	}
	public function group()
	{
		require_once('components/com_user/models/GroupModel.php');
		$group = new GroupModel();
		$task = Helper::checkTask('index.php?com=com_user&view=groups');
		if (!empty($_POST)) {
			$data = $_POST;
			if ($group->$task($data)) {
				header('Location: index.php?com=com_user&view=groups');
				exit();
			}
		}
		else
		{
			$temp =$group->getGroupById($_GET['id']);
			$this->results['group'] = $temp[0];
		}
		$optionCategory = '';
		$group->optionParent(0,'&nbsp;&nbsp;', $optionCategory);
		$this->parentGroup = array(
			'optionCategory' => $optionCategory
		);

	}
	public function groups()
	{
		require_once('components/com_user/models/GroupsModel.php');
		$groups = new GroupsModel();
		$this->results['groups'] = $groups->getList();
		if (!empty($_POST)) {
			$task = $_POST['task'];
			$groups->$task($_POST['id']);
			header('Location: index.php?com=com_user&view=groups');
			exit();
		}
	}
	public function addgroup(){
		$title = $_POST['title'];
		$status = $_POST['status'];
		$parent_id = $_POST['parent_id'];
		$parameters = $_POST['parameters'];
		$notes = $_POST['notes'];
		$this->group->addgroup($title,$status,$parent_id,$parameters,$notes);
	}
	public function getGroupById($id)
	{
		$this->group->getGroupById($id);
	}
}